<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /*
  初始时令 X=0 遍历字符串数组 operations，遇到 “++x” 或 “x++” 时，
  将 x 加 1 ，否则将 x 减 1 
    */
    var finalValue = function (operations) {
      let x = 0;
      for (const op of operations) {
        if ("X++" === op || "++X" === op) {
          x++;
        } else {
          x--;
        }
      }
      return x;
    };
    console.log(finalValue())
  </script>
</body>

</html>